{__NOLAYOUT__}

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="renderer" content="webkit">
    <link href="__STATIC__/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <script src="__STATIC__/jquery-3.3.1.min.js"></script>
    <script src="__STATIC__/jquery.form.min.js"></script>
    <script src="__STATIC__/bootstrap/js/bootstrap.min.js"></script>
    <link href="__STATIC__/style.css" rel="stylesheet">
    <script src="__STATIC__/layer/layer.js"></script>
    <script src="__STATIC__/xlsx.full.min.js"></script>
    <script src="__STATIC__/myui/import.xlsx.js"></script>
</head>
<style>
    .text{
        border: 1px solid rgb(204,204,204);
        border-radius: 4px;
        padding: 5px;
    }
    .text div{
        padding: 5px;
    }
    .my-input{
        width: 100px;
        display: inline-block;
        margin-right: 20px;
    }
</style>
<body>
<div class="container">
    <div class="row" style="margin-top: 20px;">
        <div class="col-sm-12" style="padding-left: 0px;">
            <button class="btn btn-success btn-sm" onclick="importTmp()">导入模板</button>
            <label>起始行：</label>
            <input type="number" id="startRow" class="form-control my-input">
            <label>结束行：</label>
            <input type="number" id="endRow" class="form-control my-input">
            <button class="btn btn-info" onclick="clickSelectFile()">选择文件</button>
            <input type="file" id="excel-file" onchange="onChangeFile(this)" style="display: none;"
                   accept="application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
        </div>
    </div>
</div>
</body>
<script>

    function clickSelectFile() {
        var start = parseInt( $("#startRow").val() );
        var end = parseInt( $("#endRow").val() );
        console.log(start,end);
        if(isNaN(start)|| isNaN(end) || start == '' || end == '' || start <= 0 || end <= 0 || start > end){
            layer.alert('请输入正确的起始行和结束行');
            return;
        }

        $('#excel-file').click();
    }

    function onChangeFile(obj) {
        var start = parseInt( $("#startRow").val() );
        var end = parseInt( $("#endRow").val() );
        var cols = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V',
            'W','X','Y','Z','AA','AB','AC','AD','AE','AF','AG','AH','AI','AJ','AK','AL','AM','AN','AO','AP',
            'AQ','AR','AS','AT','AU','AV','AW','AX','AY','AZ','BA','BB','BC','BD','BE','BF'];
        importf(obj,start,end,cols,getExcelData);
        $(obj).val('');
    }

    function getExcelData(data) {
        if(data == null){
            layer.alert('读取文件数据失败',{icon:2});
        }
        // console.log(data);
        var start = parseInt( $("#startRow").val() );
        var postData = JSON.stringify(data);
        var base64 = new Base64();
        postData = base64.encode(postData);
        layer.load();
        $.ajax({
            url:"{:url('import')}",
            type:'post',
            data:{data:postData,start:start},
            success:function (text) {
                layer.closeAll('loading');
                var json = JSON.parse(text);
                console.log(json);
                if(json['code'] == '200'){
                    layer.alert(json['msg'],{icon:1});
                }
                else{
                    layer.alert(json['msg'],{icon:2});
                }
            },
            error:function (text) {
                layer.closeAll('loading');
                layer.alert('网络错误',{icon:2});
            }
        })
    }

    function importTmp() {
        location.href = "__STATIC__/tmp/在建工程房屋构筑物导入模板.xlsx";
    }

</script>
</html>